package com.codebo.homiematchbackend.manager;

import com.codebo.homiematchbackend.config.CosClientConfig;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.COSObject;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.io.File;

@Slf4j
@Service
public class CosManager
{
    @Resource
    private COSClient cosClient;

    @Resource
    private CosClientConfig cosClientConfig;

    public PutObjectResult putObject(String key, File file)
    {

        PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key, file);
        return cosClient.putObject(putObjectRequest);

    }

    public COSObject getObject(String key)
    {
        return cosClient.getObject(cosClientConfig.getBucket(), key);
    }

    public void deleteObject(String key)
    {
        cosClient.deleteObject(cosClientConfig.getBucket(), key);
    }
}
